﻿using System.Threading;

using Ycg.Logging.Configuration.ConfigurationInfos;
using Ycg.Logging.Layout;
using Ycg.Utility;

namespace Ycg.Logging.Targets
{
    internal class FileLogTarget : LogTarget
    {
        private static readonly object Obj = new object();

        public override void Write(LogInfo logInfo)
        {
            ThreadPool.QueueUserWorkItem(p =>
            {
                lock (Obj)
                {
                    string filePath = FileLogTargetConfigurationInfo.Instance.Path;
                    string fileName = logInfo.Date.ToString("yyyy-MM-dd") + "-" + logInfo.LogLevel + ".txt";
                    FileHelper.AppendContent(filePath + fileName, new DefaultLayout().ToString(logInfo), true);
                }
            });
        }
    }
}
